//
//  MultiLanguageButton.m
//  pa
//
//  Created by HaiJiao Chen on 12-7-21.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import "MultiLanguageButton.h"
#import "FilePack.h"

@implementation MultiLanguageButton
@synthesize textID;

-(id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self)
    {
        textID = -1;
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(languageChange:) name:MultiLanguageChangeNotification object:nil];
    }
    return self;
}

- (id)initWithCoder:(NSCoder *)aDecoder
{
    self = [super initWithCoder:aDecoder];
    if (self)
    {
        textID = [[self titleForState:UIControlStateNormal] intValue];
        [self setTitle:[FilePack getStringByID:textID] forState:UIControlStateNormal];
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(languageChange:) name:MultiLanguageChangeNotification object:nil];
    }
    return self;
}

- (void)setTextID:(int)_textID
{
    if (textID != _textID)
    {
        textID = _textID;
        [self setTitle:[FilePack getStringByID:textID] forState:UIControlStateNormal];
    }
}

- (void)dealloc
{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
    [super dealloc];
}

- (void)languageChange:(NSNotification* )note
{
    //NSString* lan = [note object];
    [self setTitle:[FilePack getStringByID:textID] forState:UIControlStateNormal];
}

@end
